﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using SelfService.Model.Models;


namespace SelfService.ViewModel.SysAppointmentVMs
{
    public partial class SysAppointmentListVM : BasePagedListVM<SysAppointment_View, SysAppointmentSearcher>
    {

        protected override IEnumerable<IGridColumn<SysAppointment_View>> InitGridHeader()
        {
            return new List<GridColumn<SysAppointment_View>>{
                this.MakeGridHeader(x => x.OrderId),
                this.MakeGridHeader(x => x.HospitalId),
                this.MakeGridHeader(x => x.DepartmentId),
                this.MakeGridHeader(x => x.DepartmentName),
                this.MakeGridHeader(x => x.ClinicUnitId),
                this.MakeGridHeader(x => x.DoctorId),
                this.MakeGridHeader(x => x.DoctorLevelCode),
                this.MakeGridHeader(x => x.AppointmentDate),
                this.MakeGridHeader(x => x.ScheduleId),
                this.MakeGridHeader(x => x.TimeSelectionId),
                this.MakeGridHeader(x => x.TimeSelectionStart),
                this.MakeGridHeader(x => x.TimeSelectionEnd),
                this.MakeGridHeader(x => x.HealthCardNo),
                this.MakeGridHeader(x => x.PatientId),
                this.MakeGridHeader(x => x.PatientName),
                this.MakeGridHeader(x => x.IdCardNo),
                this.MakeGridHeader(x => x.Phone),
                this.MakeGridHeader(x => x.OrderTime),
                this.MakeGridHeader(x => x.AppointmentFee),
                this.MakeGridHeader(x => x.TreatFee),
                this.MakeGridHeader(x => x.Type),
                this.MakeGridHeader(x => x.Status),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysAppointment_View> GetSearchQuery()
        {
            var query = DC.Set<SysAppointment>()
                .CheckContain(Searcher.OrderId, x=>x.OrderId)
                .CheckContain(Searcher.HospitalId, x=>x.HospitalId)
                .CheckContain(Searcher.DepartmentId, x=>x.DepartmentId)
                .CheckContain(Searcher.DepartmentName, x=>x.DepartmentName)
                .CheckContain(Searcher.ClinicUnitId, x=>x.ClinicUnitId)
                .CheckContain(Searcher.DoctorId, x=>x.DoctorId)
                .CheckContain(Searcher.DoctorLevelCode, x=>x.DoctorLevelCode)
                .CheckBetween(Searcher.AppointmentDate?.GetStartTime(), Searcher.AppointmentDate?.GetEndTime(), x => x.AppointmentDate, includeMax: false)
                .CheckContain(Searcher.ScheduleId, x=>x.ScheduleId)
                .CheckContain(Searcher.HealthCardNo, x=>x.HealthCardNo)
                .CheckContain(Searcher.PatientId, x=>x.PatientId)
                .CheckContain(Searcher.PatientName, x=>x.PatientName)
                .CheckContain(Searcher.IdCardNo, x=>x.IdCardNo)
                .CheckContain(Searcher.Phone, x=>x.Phone)
                .CheckBetween(Searcher.OrderTime?.GetStartTime(), Searcher.OrderTime?.GetEndTime(), x => x.OrderTime, includeMax: false)
                .CheckEqual(Searcher.Type, x=>x.Type)
                .CheckEqual(Searcher.Status, x=>x.Status)
                .Select(x => new SysAppointment_View
                {
				    ID = x.ID,
                    OrderId = x.OrderId,
                    HospitalId = x.HospitalId,
                    DepartmentId = x.DepartmentId,
                    DepartmentName = x.DepartmentName,
                    ClinicUnitId = x.ClinicUnitId,
                    DoctorId = x.DoctorId,
                    DoctorLevelCode = x.DoctorLevelCode,
                    AppointmentDate = x.AppointmentDate,
                    ScheduleId = x.ScheduleId,
                    TimeSelectionId = x.TimeSelectionId,
                    TimeSelectionStart = x.TimeSelectionStart,
                    TimeSelectionEnd = x.TimeSelectionEnd,
                    HealthCardNo = x.HealthCardNo,
                    PatientId = x.PatientId,
                    PatientName = x.PatientName,
                    IdCardNo = x.IdCardNo,
                    Phone = x.Phone,
                    OrderTime = x.OrderTime,
                    AppointmentFee = x.AppointmentFee,
                    TreatFee = x.TreatFee,
                    Type = x.Type,
                    Status = x.Status,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysAppointment_View : SysAppointment{

    }
}
